﻿Imports System.Windows.Forms
Imports System.Data
Imports System.Data.OracleClient
Imports Barra

Public Class Frm_Despacho
    Dim VectorDeDatos(5) As TextBox
    'conexion para inicializar la barra del navegador
    Dim conexion As String = "Driver={Microsoft ODBC for Oracle};Server=xe;Uid=redes;Pwd=redes;"
    'query para el dgv
    Dim querydgv As String = " select id_transaccion as Codigo, id_entrega as entrega, fecha as Fecha, hora as Hora, estado as Estado, bodeguero as Bodeguero from TB_LOT_DESPACHO order by id_transaccion"
    Dim querycombo As String = "SELECT id_entrega from TB_INA_ENTREGA"
    Dim valuecombo As String = "id_entrega" 'valor a insertar en tabla de acuerdo al combo
    Dim displaycombo As String = "id_entrega" 'valor a mostrar en el combo
    'variable para llevar la secuencia en el campo ID
    Dim querysecuencia As String = "select max(ID_TRANSACCION)+ 1 as ID_TRANSACCION from TB_LOT_DESPACHO"
    Dim camposecuencia As String = "ID_TRANSACCION"
    Public Function LlenarVector() As TextBox()
        VectorDeDatos(0) = TXTTRA
        VectorDeDatos(1) = TXTEN
        VectorDeDatos(2) = TXTFE
        VectorDeDatos(3) = TXTHO
        VectorDeDatos(4) = TXTES
        VectorDeDatos(5) = TXTBOD
        Return VectorDeDatos
    End Function
    Private Sub Frm_Despacho_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        VectorDeDatos = LlenarVector()
        BarraNavegacion1.Inicializar("Driver={Microsoft ODBC for Oracle};Server=xe;Uid=redes; Pwd=redes;", "TB_LOT_DESPACHO", VectorDeDatos)
        'para llevar la secuencia del codigo
        funciones.llenarcombo(CMBEN, querycombo, valuecombo, displaycombo)
        'llenado del combo
        Dim temp As String = funciones.traersecuencia(querysecuencia, camposecuencia)
        'llenado del datagridview
        DGVDS.DataSource = funciones.LlenarDgv(querydgv)
        If temp = "" Then
            TXTTRA.Text = "1"
        Else
            TXTTRA.Text = temp
        End If
        Dim Cmb_estado() As String = {"Entregado", "Pendiente", "Ruta"}
        Cmbestent.Items.AddRange(Cmb_estado)
        Dim Cmb_bodeguero() As String = {"Rivera Mejía", "Sanchez Gonazles", "Moreira Velazquez"}
        cmbbodeguero.Items.AddRange(Cmb_bodeguero)
    End Sub

    Private Sub TXTTRA_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TXTTRA.TextChanged
        Dim temp As String = funciones.traersecuencia(querysecuencia, camposecuencia)
        If temp = "" Then
            TXTTRA.Text = "1"
        Else
            TXTTRA.Text = temp
        End If
    End Sub

    Private Sub CMBEN_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CMBEN.SelectedIndexChanged
        'para que el textbox oculto tome el valor del combo
        If CMBEN.ValueMember.Any Then
            TXTEN.Text = CMBEN.SelectedValue
        End If
    End Sub

    Private Sub TXTEN_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TXTEN.TextChanged

    End Sub

    
    Private Sub Cmbestent_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cmbestent.SelectedIndexChanged
        TXTES.Text = Cmbestent.SelectedItem
    End Sub

    Private Sub cmbbodeguero_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbbodeguero.SelectedIndexChanged
        TXTBOD.Text = cmbbodeguero.SelectedItem
    End Sub
End Class
